package ui.robots_wicket;

import org.apache.wicket.Page;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.CompoundPropertyModel;
import unq.uis.robots.applicationsModels.JugadorVista;
import unq.uis.robots.applicationsModels.PelearApplicationModel;

public class IngresarApuestaPage extends WebPage{
	private static final long serialVersionUID = 1L;
	private Page mainPage;
	private Page anteriorPage;
	private JugadorVista jugadorVista;
	private PelearApplicationModel pelearApplicationModel;	

	public IngresarApuestaPage(Page anterior,Page mainPage,PelearApplicationModel pelearApplicationModel) {
		this.mainPage = mainPage;
		this.anteriorPage = anterior;
		this.jugadorVista = (JugadorVista)mainPage.getDefaultModelObject();		
		this.pelearApplicationModel = pelearApplicationModel;
		Form<?> form = new FormCopado("form", new CompoundPropertyModel<PelearApplicationModel>(this.pelearApplicationModel));
		form.add(new TextField<String>("apuesta"));
		form.add(new FeedbackPanel("feedbackPanel"));
		this.agregarLabels(form);
		this.agregarBotones(form);		
		this.add(form);
	}
	
	public void agregarLabels(Form<?> form){
		form.add(new Label("robotPropio.nombre"));
		form.add(new Label("robotContrincante.nombre"));
		form.add(new Label("nombreJugador",this.jugadorVista.getNombre()));
		form.add(new Label("dineroJugador",((Integer)this.jugadorVista.getDinero()).toString()));
	}
	
	public void agregarBotones(Form<?> form){		
		form.add(new BotonCopado("aceptar") {
			static final long serialVersionUID = 1L;

			@Override
			public void execute() {
				IngresarApuestaPage.this.pelearApplicationModel.pelear();
				this.setResponsePage(new ResultadoCompetenciaPage(mainPage, pelearApplicationModel));
				
			}
			
		});
		
		Button cancelButton = new Button("cancelar"){
			private static final long serialVersionUID = 1L;

			@Override
			public void onSubmit() {
				this.setResponsePage(anteriorPage);
			}
		};
		cancelButton.setDefaultFormProcessing(false);
		form.add(cancelButton);
	}	

}
